const moment = require('moment');
module.exports = app => {
  const {STRING, BIGINT,DATE,TEXT} = app.Sequelize;

  const User = app.model.define('user', {
    id: {
      type: BIGINT,
      primaryKey: true,
      autoIncrement: true,
    },
    user_name: STRING(100),
    password: STRING(300),
    //以此为分界线
    user_id: BIGINT,
    real_name: STRING(32),
    nick_name: STRING,
    email: STRING,
    mobile: STRING(16),
    avatar: STRING(128),
    gender: TEXT('tiny'), // 性别：1->男 2->女 0->保密
    user_type: TEXT('tiny'), // 用户权限：1->管理员 2->编辑 0->注册会员
    grade_name: STRING(128),
    grade_value: STRING(3),
    org_node_name: STRING(128),
    create_time: {
      type:DATE,
      get(){
        return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    update_time: {
      type:DATE,
      get(){
        return moment(this.getDataValue('update_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    created_ip: BIGINT(12),
    updated_ip: BIGINT(12),
  }, {
    tableName: 'hy_user',
    timestamps: false,
  });

  return User;
};
